package com.mxpio.erp.common.workshop.entity;

import com.mxpio.erp.common.jpa.model.Notice;
import com.mxpio.erp.common.jpa.model.NoticeLine;
import com.mxpio.erp.common.technology.entity.WorkShop;
import com.mxpio.erp.common.vo.OrderExcuteLineVo;
import com.mxpioframework.security.annotation.Dict;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.math.BigDecimal;
import java.util.List;

/**
 * @Author : 吴盼盼
 * @Datetime : 2022/11/14 11:32
 * @Desc :
 * @Modor :  Modifytime:
 * @modDesc :
 */
@Data
@EqualsAndHashCode(callSuper=false)
@Entity
@Table(name = "MB_ERP_WORKSHOP_DEFECTIVE_NOTICE")
@Schema(description="不良品处理通知单")
public class DefectiveProductsNotice extends Notice {
	private static final long serialVersionUID = 1L;

    @Column(name = "PRODUCT_ITEM_CODE_")
    @Schema(description = "产品编号")
    private String productItemCode;

    @Column(name = "PRODUCT_ITEM_NAME_")
    @Schema(description = "产品名称")
    private String productItemName;
    @Column(name = "ORDER_QANTITY_")
    @Schema(description = "订单数量")
    private BigDecimal orderQuantity;
    @Column(name = "PRODUCT_DRAWING_NO_")
    @Schema(description = "图号")
    private String productDrawingNo;
    @Column(name = "MAIN_WORKSHOP_")
    @Schema(description = "主制车间")
    @Dict(dicCode = "workShopCode",dicEntity = WorkShop.class,dicText = "workShopName")
    private String mainWorkshop;

	@Transient
    private List<DefectiveProductsNoticeLine> defectiveProductsNoticeLines;
    @Override
    public List<? extends NoticeLine> getNoticeLines() {
        return this.defectiveProductsNoticeLines;
    }

    @Override
    public String initTypeCode() {
        return "DP1";
    }

    @Transient
    private ManufactureOrder order;//业务单据
    @Override
    public DefectiveProductsNoticeLine createLine(OrderExcuteLineVo orderExcuteVo) {
        DefectiveProductsNoticeLine noticeLine = new DefectiveProductsNoticeLine();
        noticeLine.setOriginBizLineNo(orderExcuteVo.getBizOrderlineNo());
        noticeLine.setOriginBizNo(orderExcuteVo.getBizOrderNo());
        noticeLine.setItemCode(orderExcuteVo.getItemCode());
        noticeLine.setNoticeNo(this.getNoticeNo());
        noticeLine.setQuantity(orderExcuteVo.getQuantity());
        noticeLine.setSort(orderExcuteVo.getSort());
        noticeLine.setLotNo(orderExcuteVo.getLotNo());
        noticeLine.setSubLotIndex(orderExcuteVo.getSubLotIndex());
        noticeLine.setReporter(orderExcuteVo.getReporter());
        noticeLine.setReportProc(orderExcuteVo.getReportProc());
        noticeLine.setExceptionType(orderExcuteVo.getExceptionType());
        noticeLine.setDefectiveReason(orderExcuteVo.getDefectiveReason());
        noticeLine.setDefectiveDesc(orderExcuteVo.getDefectiveDesc());
        noticeLine.setResponseUnit(orderExcuteVo.getResponseUnit());
        noticeLine.setSupplementFlag(orderExcuteVo.getSupplementFlag());//记录是否补料
        noticeLine.setBomWhCode(orderExcuteVo.getBomWhCode());//订单bom行对应仓库code
        return noticeLine;
    }
}
